package top.mask.mq.two;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import top.mask.mq.utils.RabbitMQUtil;

/**
 * 这是一个工作线程-消费者
 */
@Slf4j
public class Worker02 {
    //队列名称
    public static final String QUEUE_NAME = "hello";

    //接收消息
    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMQUtil.getChannel();


        DeliverCallback deliverCallback = (consumerTag,message) ->
                log.info("接收消息[{}]成功",new String(message.getBody()));


        CancelCallback cancelCallback = consumerTag ->
                log.info("消息者取消消接口回调逻辑{[]}",consumerTag);




        log.info("C2等待接收消息...");
        //消息的接收
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
